<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改工厂')"/>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-factory-edit" th:object="${factory}">
        <input id="factoryId" name="factoryId" type="hidden" th:field="*{factoryId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">工厂名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="factoryName" id="factoryName" th:field="*{factoryName}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">仓库：</label>
            <div class="col-sm-8">
                <select id="wareId" name="wareId" class="form-control" v-model="checkWare">
                    <option v-for="ware in wares" :value="ware.wareId" v-cloak>{{ware.wareName}}</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">地址：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="addr" id="addr" th:field="*{addr}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">邮箱：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="email" id="email" th:field="*{email}" required>
            </div>
        </div>
    </form>
    <form th:object="${factory}">
        <input id="checkWare" type="hidden" th:field="*{wareId}"/>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    function edit(){
        var factoryId = $("input[name='factoryId']").val();
        var factoryName = $("input[name='factoryName']").val();
        var addr = $("input[name='addr']").val();
        var email = $("input[name='email']").val();
        var wareId = $("select[name='wareId']").val();
        $.ajax({
            cache: true,
            type: "POST",
            url: ctx + "system/factory/edit",
            data: {
                "factoryId": factoryId,
                "factoryName": factoryName,
                "addr": addr,
                "email": email,
                "wareId": wareId
            },
            async: false,
            error: function(request){
                $.modal.alertError("系统错误");
            },
            success: function(data){
                $.operate.successCallback(data);
            }
        });
    }

    function submitHandler(){
        if($.validate.form()){
            edit();
        }
    }

    var app = new Vue({
        el: '.wrapper',
        data: {
            wares: [],
            checkWare: ''
        },
        methods: {
            getWares: function(){
                var that = this;
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/system/wareInfo/list",
                    data: {},
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        that.wares = data.rows;
                    }
                });
            }
        },
        created(){
            this.getWares();
            this.checkWare = document.getElementById('checkWare').value;
        }
    })
</script>
</body>
</html>